What is run-applescript?
The run-applescript npm package allows Node.js applications to execute AppleScript code directly from JavaScript. This enables developers to automate tasks on macOS, interact with the system and applications in a more integrated manner, and leverage the full power of AppleScript without leaving the Node.js environment.
What are run-applescript's main functionalities?
Executing simple AppleScript commands
This feature allows you to execute straightforward AppleScript commands. The example provided opens a new Finder window on macOS.
const runApplescript = require('run-applescript');
runApplescript('tell app "Finder" to make new Finder window').then(() => {
console.log('Finder window opened.');
});
Getting output from AppleScript
This feature enables the execution of AppleScript commands that return output. The example demonstrates how to get the current volume settings.
const runApplescript = require('run-applescript');
runApplescript('get volume settings').then((output) => {
console.log(output);
});
Handling errors in AppleScript execution
This feature is crucial for robust error handling in your application. It allows you to catch and handle errors that occur during the execution of AppleScript commands. The example tries to execute an invalid command, which results in an error.
const runApplescript = require('run-applescript');
runApplescript('invalid command').catch((error) => {
console.error('AppleScript Error:', error);
});
Other packages similar to run-applescript
osascript
Similar to run-applescript, the osascript package allows for the execution of AppleScript and JavaScript for Automation (JXA) scripts from Node.js. It provides a similar interface but also supports executing JXA scripts, offering a broader range of scripting capabilities on macOS.
node-osascript
This package also enables the execution of AppleScript from Node.js applications. It is similar to run-applescript but differs in its API and the way it handles script execution and output. node-osascript might offer alternative approaches or additional options for script execution that run-applescript does not.
run-applescript
Run AppleScript and get the result
Install
$ npm install --save run-applescript
Usage
const runApplescript = require('run-applescript');
runApplescript('return "unicorn"').then(result => {
console.log(result);
});
License
MIT © Sindre Sorhus